package airthmetic.exercise.linkedList;

import java.util.PriorityQueue;

public class _148_排序链表 {
    public static ListNode sortList(ListNode head) {
        PriorityQueue<Integer> queue = new PriorityQueue();
        while(head != null){
            queue.offer(head.val);
            head = head.next;
        }

        ListNode res = new ListNode(-1);
        ListNode current = res;
        while (!queue.isEmpty()){
            current.next = new ListNode(queue.poll());
            current = current.next;
        }
        return res.next;
    }

    public static void main(String[] args) {
        ListNode listNode4 = new ListNode(1, null);

        ListNode listNode3 = new ListNode(4, listNode4);
        ListNode listNode2 = new ListNode(2, listNode3);
        ListNode listNode = new ListNode(5, listNode2);


        System.out.println(sortList(listNode));
    }
}
